<?php
	session_start();	
	
		if(!isset($_SESSION['myusername'])){
		echo "Niet ingelogd <br/>";
		header ('location: niet_ingelogd_bestel.php');
	}
	
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>

	<title>PizzaRio ~ voor al uw zelfgemaakte pizza's!</title>
	
	<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />
	<link rel="stylesheet" href="css/jquery.jcarousel.css" type="text/css" media="all" />
	<!--[if IE 6]>
		<link rel="stylesheet" href="css/ie6.css" type="text/css" media="all" />
	<![endif]-->
	<link rel="icon" href="css/images/favicon.ico" type="image/x-icon" />
	<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
	<script type="text/javascript" src="js/jquery.jcarousel.pack.js"></script>
	<script type="text/javascript" src="js/func.js"></script>
	
	<script type="text/javascript" src="js/Scrolling.js"></script>
    	
</head>

<body>

<!-- Topvakje links bovenin -->
<div class="shell">
	<div class="border">
		<div id="header">
			<img src="css/images/logo.gif" alt="PizzaRio ~ voor al uw zelfgemaakte pizza's!" />
			<div class="socials right">
				<ul>
				    <li><a href="#" class="rss">RSS</a></li>
				    <li><a href="http://www.facebook.com" class="fb">Facebook</a></li>
				    <li class="last"><a href="http://www.twitter.com" class="twit">Twitter</a></li>
				</ul>
				<div>
					 <ul>
					 		 <li>
								<form name="form1" method="post" action="login/checklogin.php">
								<input type="hidden" name="submitted" value="true" />
							 		<input name="myusername" type="text" id="myusername" value="Gebruikersnaam">
							 </li>
							 <li>
							 <input name="mypassword" type="password" id="mypassword" value="wachtwoord">
							 </li>
					 </ul>
					 <ul>
						<li><input type="submit" name="Submit" value="Login" width="200px">
						</form></li>
					 </ul>
					 
					 <ul>
						<?php
							if(isset($_SESSION['submitted'])){
								if(($_SESSION['submitted']) > 1){
									echo "Al ingelogd. <br />";
								}
							}	
							if(isset($_SESSION['myusername'])){
								Echo "<li>Welkom ". $_SESSION['klantgev']['naam'] . "</li>";
								Echo "<li><a href=\"gegevens.php\">gegevens</a></li>";
								echo "<li><a href=\"huidige_order.php\">Order</a></li>";
								Echo "<li><a href=\"Logout.php\">logout</a></li>";		
							}
							if(!isset($_SESSION['myusername'])){
								Echo "<li>Welkom Gast</li>";
								Echo "<li>Registreer <a href=\"registreer.php\">Hier</a></li>";		
							}
							if(isset($_SESSION['members'])){
								if($_SESSION['members']['niveau_id'] >= 2){
									echo "<li><a href=\"backend/back_end.php\">Backend</a></li>";
								}
							}						
						?>
						
				<ul>
			 </div>
			</div>

			<div class="cl">&nbsp;</div>
		</div>
		
		<div id="navigation">
			<ul>
			    <li><a href="index.php" class="active">Home</a></li>
			  
			    <li><a href="menu.php">Menu</a></li>
				<li><a href="aanbiedingen.php">Aanbiedingen</a></li>
			    <li><a href="samenstellen.php">Maken</a></li>
			    <li><a href="mijnpizzas.php">Mijn Pizza's</a></li>
				<li><a href="pizzaszoeken.php">Zoek</a></li>
			
			</ul>
			<div class="cl">&nbsp;</div>
		</div>
		
		<div class="slider">
			<div class="slider-nav">
				<a href="index.html" class="left notext">1</a>
				<a href="#" class="left notext">2</a>
				<a href="#" class="left notext">3</a>
				<div class="cl">(iets)?</div>
			</div>
			<ul>
			    <li>
			    	<div class="item">
						<div class="text">
						</div>
			    		<img src="css/images/slider01.png" alt="Welkom bij PizzaRio!" />
			    	</div>
			    </li>
			    <li>
			    	<div class="item">
						<div class="text">
						</div>
			    		<img src="css/images/slider02.png" alt="" />
			    	</div>
			    </li>
			    <li>
			    	<div class="item">
						<div class="text">
						</div>
			    		<img src="css/images/Slider03.png" alt="Maak je eigen pizza!" />
			    	</div>
			    </li>
			</ul>
		</div>
		
		<div id="main">
			<div id="pizza_lijst">
				<div class="highlight">
				<?php					
						include 'database.php';
						echo "<img src='css/images/Bestellen.png' alt='PizzaRio ~ voor al uw zelfgemaakte pizzas!' />";
						echo "<br/><br/>";

						
						if($_POST['submit']){							

							$klant_id = $_SESSION['members']['id'];
							$totaal_prijs = $_POST['totaal_prijs'];
							$order_id = $_SESSION['orderid'];
							$punten_min = $_POST['punten_min'];
							
							$sql4 = "UPDATE gegevens SET punten = punten-$punten_min WHERE klantid='$klant_id'";
							mysqli_query($dbcon, $sql4);
						
							
							$sql = "INSERT INTO order_besteld (id, orderid, klantid, status, betaling, datum, totaal_prijs) VALUES ('null', '".$_SESSION['orderid']."', '$klant_id', '1', '1', now(), '$totaal_prijs' )";
							mysqli_query($dbcon, $sql);
														
							
							$query = "SELECT * FROM orders WHERE orderid = '$order_id'";
							$result = mysqli_query($dbcon, $query) or die();							
							
							while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){											
								$pizza_id = $row['pizzaid'];								
								$sql2 = "UPDATE pizza SET counter=counter+1 WHERE id = '$pizza_id'";
								mysqli_query($dbcon, $sql2);
								
								$sql3 = "UPDATE gegevens SET punten=punten+1 where klantid = (SELECT id_customer FROM pizza WHERE id = '$pizza_id')";
								mysqli_query($dbcon, $sql3);
								

							$query2 = "SELECT id_cheese FROM cheese_pizza WHERE id_pizza = '$pizza_id'";
							$result2 = mysqli_query($dbcon, $query2) or die();       
								   
								while($row2 = mysqli_fetch_array($result2, MYSQLI_ASSOC)){
										   
								$cheese_id = $row2['id_cheese'];								
										
								$query3 = "UPDATE cheese SET quantity = quantity + 1 WHERE id = '$cheese_id'";
								mysqli_query($dbcon, $query3);           
								}		
								
								
								$query5 = "SELECT id_meat FROM meat_pizza WHERE id_pizza = '$pizza_id'";
							$result5 = mysqli_query($dbcon, $query5) or die();       
								   
								while($row5 = mysqli_fetch_array($result5, MYSQLI_ASSOC)){
										   
								$meat_id = $row5['id_meat'];								
										
								$query6 = "UPDATE meat SET quantity = quantity + 1 WHERE id = '$meat_id'";
								mysqli_query($dbcon, $query6);           
								}		
								
								$query7 = "SELECT id_herbs FROM herbs_pizza WHERE id_pizza = '$pizza_id'";
							$result7 = mysqli_query($dbcon, $query7) or die();       
								   
								while($row6 = mysqli_fetch_array($result7, MYSQLI_ASSOC)){
										   
								$herbs_id = $row6['id_herbs'];								
										
								$query8 = "UPDATE herbs SET quantity = quantity + 1 WHERE id = '$herbs_id'";
								mysqli_query($dbcon, $query8);           
								}		
								
								$query9 = "SELECT id_fruit FROM fruit_pizza WHERE id_pizza = '$pizza_id'";
								$result9 = mysqli_query($dbcon, $query9) or die();       
								   
								while($row7 = mysqli_fetch_array($result9, MYSQLI_ASSOC)){
										   
								$fruit_id = $row7['id_fruit'];								
										
								$query10 = "UPDATE fruit SET quantity = quantity + 1 WHERE id = '$fruit_id'";
								mysqli_query($dbcon, $query10);           
								}	
								
								$query11 = "SELECT id_sauce FROM sauce_pizza WHERE id_pizza = '$pizza_id'";
								$result11 = mysqli_query($dbcon, $query11) or die();       
								   
								while($row8 = mysqli_fetch_array($result11, MYSQLI_ASSOC)){
										   
								$sauce_id = $row8['id_sauce'];								
										
								$query12 = "UPDATE sauce SET quantity = quantity + 1 WHERE id = '$sauce_id'";
								mysqli_query($dbcon, $query12);           
								}								
							}	
							
							Echo "Order #".$_SESSION['orderid']." Besteld.";
							
							unset($_SESSION['orderid']);
							
						}

					?>	
					
					
				</div>
			</div>
			
			
			<div class="cl">&nbsp;</div>
		</div>
		
		<div class="shadow-l"></div>
		<div class="shadow-r"></div>
		<div class="shadow-b"></div>
	</div>
	
	<div id="footer">
		<div class="footer-nav left">
			<ul>
			    <li><a href="index.html">Home</a></li>
			    <li><a href="pizzario.html">Over PizzaRio</a></li>
			    <li><a href="menu.html">Menu</a></li>
			    <li><a href="bestsellers.html">Bestsellers</a></li>
			    <li><a href="inloggen.html">Inloggen</a></li>
			    <li class="last"><a href="contact.html">Contact</a></li>
			</ul>
		</div>
		<p class="copy right">Copyright &copy; PizzaRio ~ 2012 </p>
		<div class="cl">&nbsp;</div>
	</div>
</div>
</body>
</html>